var commentDao = require('../dao/comment.js');
var blogDao = require('../dao/blog.js');
var check = require('../middlewares/check.js');
module.exports = function (app) {
	app.post('/comment/addComment',check.checkLogin,function (req,res) {
		var blog_id = req.body.blog_id;
		var user_id = req.body.user_id;
		var comment = req.body.comment;
		var user_name = req.body.user_name;
		commentDao.addComment(blog_id,user_id,user_name,comment,function (isSuccess,cm) {
			if(!isSuccess){
				res.json({
					status:isSuccess,
					comment:cm,
					blog:null
				});
			}else{
				blogDao.commentBlog(blog_id,function (isSu,blog) {
					res.json({
						status:isSuccess,
						comment:cm,
						blog:blog
					});
				});
			}
		});
	});


	app.get('/comment/getComments',function (req,res) {
		var pageIndex = req.query.page_index;
		var blog_id = req.query.blog_id;
		commentDao.getComments(pageIndex,blog_id,function (isSuccess,comments) {
			res.json({
				status:isSuccess,
				comments:comments
			});
		});
		
	});
};